const fileUtil = require('../../../common/utils/fileUtil')
const path = require('path')
const { installPackage } = require('../../../core/pluginSetupService/installPackage')
const { createPackage } = require('../../../core/pluginSetupService/createPackage')
const { mergeBasePreloadJsFile } = require('../../../common/utils/pkgUtil')


// 用于初始化系统最基础命令，包括插件打包、插件安装等命令，其升级机制 
exports.initBasePlugin = function () {

    const plugins = fileUtil.findFolder(fileUtil.copyToTemp(fileUtil.getResoucePath('./pluginPkg')))

    for (const item of plugins) {
        const pluginPkgPath = path.join(item, 'plugin.json')
        mergeBasePreloadJsFile(pluginPkgPath, "merge")
        createPackage(pluginPkgPath).then((asarPath) => {
            mergeBasePreloadJsFile(asarPath, "restore")
            installPackage(asarPath)
        })
    }
}